package com.itheima.controller;

import com.itheima.feign.PaymentHystrixFeign;
import com.netflix.hystrix.contrib.javanica.annotation.DefaultProperties;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Slf4j
@DefaultProperties(defaultFallback = "paymentInfo_Global_FollbackMethod")
public class OrderHystirxController {

    @Autowired
    private PaymentHystrixFeign paymentHystrixFeign;

    @GetMapping("/consumer/payment/hystrix/ok/{id}")
    public String paymentInfo_OK(@PathVariable("id") Integer id) {
        return this.paymentHystrixFeign.paymentInfo_OK(id);
    }

    @GetMapping("/consumer/payment/hystrix/timeout/{id}")
  /*  @HystrixCommand(fallbackMethod = "paymentInfo_TimeOutHeandle", commandProperties = {
            @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "1500")
    })*/
    @HystrixCommand
    public String paymentInfo_TimeOut(@PathVariable("id") Integer id) {
        return this.paymentHystrixFeign.paymentInfo_TimeOut(id);
    }

    public String paymentInfo_TimeOutHeandle(Integer id) {
        return "我是消费端80,对方支付系统繁忙,请10秒后重试!!┭┮﹏┭┮";
    }

    public String paymentInfo_Global_FollbackMethod() {
        return "我是全局异常处理!!┭┮﹏┭┮";
    }

}
